package com.sea.base.floating

import android.view.View
import com.sea.base.ext.global.getCurrentMillis

/**
 * @param showMillis 展示时间
 * @param timeoutMillis 等待超时时间，等待超时后不会再展示
 * @param onShowCall 展示后回调
 * @param onHideCall 隐藏后回调
 * @param onTimeoutCall 超时没有Show导致取消后回调
 */
class GlobalFloatingQueueItem(
    val view: View,
    val showMillis: Long,
    val timeoutMillis: Long = Long.MAX_VALUE,
    val onShowCall: (() -> Unit)? = null,
    val onHideCall: (() -> Unit)? = null,
    val onTimeoutCall: (() -> Unit)? = null,
) {
    val createTime = getCurrentMillis()

    /**
     * 添加到队列
     */
    fun addItemQueue() {
        GlobalFloatingQueueManager.addItemQueue(this)
    }

    /**
     * 取消或退出
     */
    fun hideItem() {
        GlobalFloatingQueueManager.hideItem(this)
    }

    override fun equals(other: Any?): Boolean {
        if (other is GlobalFloatingQueueItem) return other.view == view
        return super.equals(other)
    }

    override fun hashCode(): Int {
        return view.hashCode()
    }
}